(function($) {
    $.gAjax = {
        link: function (url){
            var arraySplit	= url.split("?");
            var page 		= arraySplit[0];
            var param 		= arraySplit[1];
            var target 		= arraySplit[2];

            jQuery.ajax({
                type: "POST",
                url: page,
                data: param,
                beforeSend: function (){
                    jQuery.gDisplay.loadStart(target);
                },
                error: function(){
                    jQuery.gDisplay.loadError(target,"Erro ao carregar a página...");
                },
                success: function(resp){
                    jQuery.gDisplay.loadStop(target);
                    jQuery(target).html(resp);
                }
            });
        },
        load: function (page, param, target, store){
            if(store != undefined) bookmarks.sethash(store,page,target,param);
            jQuery.ajax({
                type: "POST",
                url: page,
                data: param,
                beforeSend: function (){
                    jQuery.gDisplay.loadStart(target);
                },
                error: function(){
                    jQuery.gDisplay.loadError(target,"Erro ao carregar a página...");
                },
                success: function(resp){
                    jQuery.gDisplay.loadStop(target);
                    jQuery(target).html(resp);
                }
            });
        },
        exec: function (page, param, success, error, alert, async) {
            if (async === undefined)
                async = true;
            jQuery.ajax({
                type: "POST",
                url: page,
                data: param,
                dataType: 'json',
                async: async,
                beforeSend: function (){
                    jQuery.gDisplay.loadStart('BODY');
                },
                error: function(){
                    jQuery.gDisplay.loadError('BODY',"Erro ao carregar a página...");
                },
                success: function(json){
                    jQuery.gDisplay.loadStop('BODY');
                    if (alert === undefined || alert == true)
                        jQuery.gDisplay.showAlert(json, success, error);
                    else {                        
                        if (json.status)
                            eval(success);
                        else
                            jQuery.gDisplay.showError(json.msg, error);
                    }
                }
            });
        },
        login: function (page, param, success, error) {
            jQuery.ajax({
                type: "POST",
                url: page,
                data: param,
                dataType: 'json',
                beforeSend: function (){
                    jQuery.gDisplay.loadStart('BODY');
                },
                error: function(){
                    jQuery.gDisplay.loadError('BODY',"Erro ao carregar a página...");
                },
                success: function(json){
                    jQuery.gDisplay.loadStop('BODY');
                    if (json.status)
                        eval(success);
                    else
                        jQuery.gDisplay.showError(json.msg, error);
                    
                }
            });
        }
    }
})(jQuery);